package cn.micai.base.io;

import java.io.File;

/**
 * 描述：How to move file to another directory in java
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/7 14:33
 */
public class MoveFileMain {

    public static void main(String [] args) {

        System.out.println("-----------------");
        //when source file is present
        File fileSrc = new File("src/main/resources/config/config.properties");
        File newFileDest = new File("src/main/resources/"+fileSrc.getName());
        if(fileSrc.renameTo(newFileDest)){
            System.out.println("Move operation is successful");
        }else{
            System.out.println("Move operation is unsuccessful");
        }
        System.out.println("-----------------");

        //when source file is not present
        File file = new File("src/main/resources/notExists.txt");
        File newFile = new File("xyz.txt");
        if(file.renameTo(newFile)){
            System.out.println("Move operation is successful");
        }else{
            System.out.println("Move operation is unsuccessful");
        }
        System.out.println("-----------------");

    }
}
